package com.zenithmind.exam.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 考试服务缓存配置
 * 
 * @author ZenithMind
 * @since 2024-07-01
 */
@Configuration
@EnableCaching
public class ExamCacheConfig {



    /**
     * 缓存键生成器
     */
    @Bean("examCacheKeyGenerator")
    public org.springframework.cache.interceptor.KeyGenerator keyGenerator() {
        return (target, method, params) -> {
            StringBuilder sb = new StringBuilder();
            sb.append(target.getClass().getSimpleName()).append(":");
            sb.append(method.getName()).append(":");
            for (Object param : params) {
                if (param != null) {
                    sb.append(param.toString()).append(":");
                }
            }
            return sb.toString();
        };
    }
}
